package com.lnsoft.dqfs.client.test;

import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;

public class NettyClient {
    private static final String host = "10.192.34.104";//10.192.34.104
    private static final int[] ports = new int[]{2501,2502,2503,2504,2505,2506,2507,2508,2509,2510};
    public static void main(String[] args) throws Exception{
        EventLoopGroup group = new NioEventLoopGroup();
        Bootstrap bootstrap = new Bootstrap();
        bootstrap.group(group)
                .channel(NioSocketChannel.class)
                .handler(
                        new ChannelInitializer<SocketChannel>() {
                            @Override
                            protected void initChannel(SocketChannel socketChannel) throws Exception {
                                socketChannel.pipeline().addLast(new ClientReadHandler());
                            }
                        }
                );
        for(int i=0;i<10000;i++){
            for(int port:ports){
                ChannelFuture cf = bootstrap.connect(host,port).sync();
                Channel channel = cf.channel();
                channel.writeAndFlush(Unpooled.wrappedBuffer(new byte[]{16, (byte) 199, 71, 35, 49, 22}));
            }
        }

        while(true){
            Thread.sleep(600000);
        }

    }
}
